<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_users', function (Blueprint $table) {
            /*字段配置--begin*/
            $table->bigIncrements('id')->comment('主键');
            $table->string('uuid', 64)->default('')->comment('UUID 预留字段');
            $table->string('name', 32)->default('')->comment('用户姓名');
            $table->string('nickname', 32)->default('')->comment('用户昵称');
            $table->string('email', 32)->default('')->comment('用户邮箱');
            $table->string('username', 32)->default('')->comment('登录帐户');
            $table->string('password', 64)->default('')->comment('登录密码');
            $table->string('last_token', 512)->default('')->comment('最后一次登录的last_token');
            $table->string('remember_token', 64)->default('')->comment('当前有效的token');
            $table->ipAddress('current_login_ip')->default('')->comment('当前登录IP地址');
            $table->string('current_login_ua', 255)->default('')->comment('当前登录的浏览器标识UA');
            $table->unsignedInteger('current_login_time')->default(0)->comment('当前登录时间');
            $table->unsignedInteger('login_count')->default(0)->comment('登录次数');
            $table->ipAddress('last_login_ip')->default('')->comment('上次登录IP');
            $table->string('last_login_ua', 255)->default('')->comment('上次登录的浏览器标识UA');
            $table->unsignedInteger('last_login_time')->default(0)->comment('上次登录时间');
            $table->unsignedTinyInteger('is_super')->default(0)->comment('是否超级管理员,0:否；1：是');
            $table->unsignedTinyInteger('is_show')->default(0)->comment('对外是否可见，0：否；1：是');
            $table->unsignedTinyInteger('is_enable')->default(0)->comment('状态：0：禁用；1：启用');
            $table->unsignedInteger('expired_time')->default(0)->comment('过期时间');
            $table->unsignedInteger('created_time')->default()->comment('创建时间');
            $table->unsignedInteger('updated_time')->default(0)->comment('更新时间');
            /*字段配置--end*/

            /*索引配置--begin*/
            $table->unique('nickname', 'nickname_unique_index');
            $table->unique('username', 'username_unique_index');
            $table->index('name', 'name_index');
            $table->index('email', 'email_index');
            $table->index('expired_time', 'expired_time_index');
            $table->index('created_time', 'created_time_index');
            $table->index('updated_time', 'updated_time_index');
            $table->index('is_enable', 'is_enable_index');
            /*索引配置--end*/

            /*基础配置--begin*/
            $table->comment = '后台-用户主表';
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
            /*基础配置--begin*/
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_users');
    }
}
